package postpic.domain.action;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * Enumeration for valid actions that can be performed by the server.
 */
public enum Action {
	
	LOGIN("login"),
	
	REGISTER("register"),
	
	UPLOAD_PIC("uploadPic"),
	
	GET_PIC("getPic"),
	
	GET_USER("getUser"),
	
	ADD_FRIEND("addFriend"),
	
	ADD_COMMENT("addComment"),
	
	GET_RECENT_PHOTOS("getRecentPhotos");
	
	
	
	private final String actionString;
	
	private static final Map<String,Action> LOOKUP = new HashMap<String,Action>();
	
	static {
	    for(Action action : EnumSet.allOf(Action.class))
	         LOOKUP.put(action.toString(), action);
	}
	
	/**
	 * Constructor for Action.
	 * @param action String
	 */
	private Action(final String action) {
		this.actionString = action;
	}
	
	/**
	 * Method toString.
	 * @return String
	 */
	public String toString() {
		return actionString;
	}
	
	/**
	 * Method getAction.
	 * @param action String
	 * @return Action
	 */
	public static Action getAction(final String action) {
		return LOOKUP.get(action);
	}
	
}
